package com.shop.product.controller;

import com.shop.common.core.domain.Result;
import com.shop.product.domain.ShopCar;
import com.shop.product.domain.ShopCarAndDetails;
import com.shop.product.service.ItemService;
import com.shop.product.vo.ItemInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.ExecutionException;

/**
 * @Author：作者姓名
 * @Package：com.shop.product.controller
 * @Project：RuoYi-Cloudnew
 * @name：ItemController
 * @Date：2024/6/6 16:31
 */
@RestController
@RequestMapping("/item")
public class ItemController {
    @Autowired
    private ItemService itemService;

    //详情页面查询
    @GetMapping("itemList")
    public Result<ItemInfo> getItemBySkuId(@RequestParam("skuId") Long skuId) throws ExecutionException, InterruptedException {
        ItemInfo itemBySkuId = itemService.getItemBySkuId(skuId);
        return Result.success(itemBySkuId);
    }

    //查询购物车列表
    @PostMapping("/shopCarList")
    public Result<List<ShopCar>>shopCarList(@RequestParam("userId") Long userId){
        List<ShopCar>list=itemService.shopCarList(userId);
        return Result.success(list);
    }

    //完成购物车的添加和购物车明细的添加
    @PostMapping("/shopCarAdd")
    public Result shopCarAdd(@RequestBody ShopCarAndDetails shopCarAndDetails){
        itemService.ShopCarAdd(shopCarAndDetails);
        return Result.success();
    }

    //完成购物车明细的删除
    @PostMapping("/shopCarDetailsDel")
    public Result shopCarDetailsDel(@RequestParam("detailsId") Long detailsId){
        itemService.ShopCarDetailsDel(detailsId);
        return Result.success();
    }

    //完成购物车明细的修改
    @PostMapping("/shopCarDetailsUpdate")
    public Result shopCarDetailsUpdate(@RequestBody ShopCarAndDetails shopCarAndDetails){
        Result result=itemService.ShopCarDetailsUpdate(shopCarAndDetails);
        return result;
    }
}
